package emulator.unittest.hardware.nmos6502.commands;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.hardware.nmos6502.commands.TAX;
import emulator.hardware.nmos6502.operands.NoOperand;

public class TAXTest {

	private Cpu6502 cpu;
	private TAX tax;

	@Before
	public void setUp() throws Exception {
		cpu = new Cpu6502();
		tax = new TAX();
	}

	@Test
	public void testTransferZero() throws EmulatorException {
		executeAndcheckTAX(0, Flags6502.FLAG_ZERO);
	}

	@Test
	public void testTransferPositive() throws EmulatorException {
		executeAndcheckTAX(5, 0);
	}

	@Test
	public void testTransferNegative() throws EmulatorException {
		executeAndcheckTAX(0x81, Flags6502.FLAG_NEGATIVE);
	}

	private void executeAndcheckTAX(int target, int expected_flags)	throws EmulatorException {
		cpu.setX(new HwByte(0xFF));
		cpu.setAccu(new HwByte(target));
		tax.execute(cpu, new NoOperand());
		assertEquals(target, cpu.getX().getNumber());
		assertEquals(target, cpu.getAccu().getNumber());
		assertEquals(new Flags6502(expected_flags), cpu.getFlags());
	}

}
